package org.cst8277.ums.nas.entity;

import lombok.Data;
import org.apache.commons.compress.utils.Lists;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

@Data
public class IpRange {
    private String startIp;
    private String endIp;
    private int num;
    private String segmentIp;
    private int position;
    private List<String> ipList = Lists.newArrayList();


    public void init() {
        int tempIndex = StringUtils.indexOf(segmentIp, "/");
        String tempString = StringUtils.substring(segmentIp, 0, tempIndex);
        int lastDotIndex = StringUtils.lastIndexOf(tempString, ".");
        int startIpInt = Integer.valueOf(StringUtils.substring(tempString, lastDotIndex + 1));
        String ipPrefix = StringUtils.substring(tempString, 0, lastDotIndex);
        startIp = ipPrefix + "." + (startIpInt + position);
        endIp = ipPrefix + "." + (startIpInt + num + position);
        for (int i = 0; i <= num; i++) {
            String tempIp = ipPrefix + "." + (startIpInt + i + position);
            ipList.add(tempIp);
        }

    }
}
